﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RN.ERP.DTO.Person;
using System.Timers;

namespace RN.ERP.BLL.LC.Utilities
{
    public class CertificateCacheManager
    {
        private class Nested
        {
            internal static readonly CertificateCacheManager Instance = new CertificateCacheManager();
            static Nested() { }
        }

        public List<CertificateCacheEntity> dataList=new List<CertificateCacheEntity>();//缓存
        private Timer m_timer;
        private double m_Interval = 60 * 60 * 1000;
        private CertificateCacheManager()
        {
            dataList = new List<CertificateCacheEntity>();
            m_timer = new Timer();
            m_timer.Interval = m_Interval;
            m_timer.Elapsed += new ElapsedEventHandler(m_timer_Elapsed);
            m_timer_Elapsed(null,null);

        }

        public static CertificateCacheManager Current
        {
            get {
                return Nested.Instance;
            }
        }

        public void Start()
        {
            m_timer.Start();
        }

        public void Stop()
        {
            m_timer.Stop();
        }
        void m_timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            try
            {
                m_timer.Stop();
                dataList = new PersonBLL().GetEmpCertificateDict(0, "");

            }
            catch (Exception ex)
            { }
            finally {
                m_timer.Start();
            }
        }
    }
}
